package rozetka.pages;

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import rozetka.utils.ReportWriter;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import rozetka.utils.User;

/**
 * Created by foneox on 31.03.2014.
 */
public class RegistrationPage extends BasePage{
    private By progressSpinnerLocator = By.cssSelector(".iform>div>div>img");

    public RegistrationPage(WebDriver driver) {
        super(driver);
    }

    public MySettingsPage createUserAccount(User user) {
        driver.findElement(By.name("title")).sendKeys(user.getUserName());
        driver.findElement(By.name("email")).sendKeys(user.getUserEmail());
        driver.findElement(By.name("password")).sendKeys(user.getUserPassword());
        driver.findElement(By.cssSelector(".button-css-green")).click();
        ReportWriter.info(user.getUserEmail() + " tried to crate account");

        (new WebDriverWait(driver, 15))
                .until(ExpectedConditions.invisibilityOfElementLocated(progressSpinnerLocator));
        if (isUserLoggedIn()){
            return new MySettingsPage(driver);
        }else{
            ReportWriter.error("User '"+user.getUserEmail()+"' did not log-in!");
            return null;

        }




    }

}
